﻿<style scoped>

    #tableStyleBizPoint + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: auto;
        line-height: 30px;
        padding: 0 5px;
    }

    .tdImg {
        width: 35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    } 


</style>

<!-- 正文开始 -->
<div class="layui-fluid" style="padding: 5px;">
    <div class="layui-card" style="box-shadow:none;">
    	<div class="layui-card-header">
    		   场景图层
			  <div class="layui-btn-group" style="float: right;">
			   	<button type="button" class="layui-btn layui-btn-sm" id="btnAddBizLayerFolder">
			   		新增
			   	</button>
			   	<button type="button" class="layui-btn layui-btn-sm" id=btnImportFileKml>
			   		导入
			   	</button>			   	
			  </div>
    	</div>
        <div class="layui-card-body" style="padding:0px;">
        	<ul id="bizLayerTree" class="ztree" style="max-height: calc(100vh - 160px);overflow-y: auto;"></ul>
        </div>
    </div>
</div>

<!-- 表单弹窗 -->
<script type="text/html" id="modelBizLayer"> 
<form id="modelBizLayerForm" lay-filter="modelBizLayerForm" class="layui-form model-form" style="padding: 1px;">
	<input name="id" type="hidden" />
	<input name="parentId" type="hidden" />
	<input name="sceneId" type="hidden" value="#(sceneId)" />
	<table class="formTable" id="modelBizLayerFormTable">
		<tr>
			<td>名称</td>
			<td colspan="3">
				<input name="name" placeholder="" autocomplete="off" type="text" class="layui-input" maxlength="50" lay-verType="tips"
				 lay-verify="required" required />
			</td>
		</tr>
		<tr>
			<td>业务编码</td>
			<td colspan="3">
				<input name="code" placeholder="" autocomplete="off" type="text" class="layui-input" />
			</td>
		</tr>
		<tr>
			<td>图标</td>
			<td colspan="3">
				<input name="icon" placeholder="" autocomplete="off" type="text" class="layui-input" />
			</td>
		</tr>
		<tr>
			<td>类型</td>
			<td colspan="3">
				<select id="lsyerTypeSelectId" name="type" lay-filter="type" lay-verify="required" required>
					<option value="">--请选择--</option>
					<option value="Folder">目录</option>
					<option value="Maps">底图目录</option>
					<option value="Points">点目录</option>
					<option value="Polylines">线目录</option>
					<option value="Polygons">面目录</option>
					<option value="Models">模型目录</option>
					<option value="Features">单体目录</option>
					<option value="VideoShed3ds">视频投影</option>
					<option value="VideoModels">视频模型</option>
					<option value="VideoPlanes">视频墙</option>
					<option value="Roams">漫游目录</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>序号:</td>
			<td colspan="3">
				<input name="sort" autocomplete="off" placeholder="请输入序号" type="number" class="layui-input" maxlength="20"
				 lay-verType="tips" lay-verify="required" required />
			</td>
		</tr>
	</table>
</form>
</script>

<script type="text/html" id="modelBizLayerExtend">
<tr class="extend">
	<td>默认样式</td>
	<td colspan="2">
		<input type="hidden" id="defaultStyleIdExtendId" name="defaultStyleId"/>
		<input id="defaultStyleIdExtendName" name="defaultStyleName" placeholder="" autocomplete="off" type="text" class="layui-input" />
	</td>
	<td colspan="1">
		<button type="button" class="layui-btn layui-btn-sm" id="defaultStyle-select-btn">选择</button>
	</td>
</tr>
<tr class="extend">
	<td>滑过样式</td>
	<td colspan="2">
		<input type="hidden" id="hoverStyleIdExtendId" name="hoverStyleId"/>
		<input id="hoverStyleIdExtendName" name="hoverStyleName" placeholder="" autocomplete="off" type="text" style="float:left;" class="layui-input" />
	</td>
	<td colspan="1">
		<button type="button" class="layui-btn layui-btn-sm" id="hoverStyle-select-btn">选择</button>
	</td>
</tr>
<tr class="extend">
	<td>选中样式</td>
	<td colspan="2">
		<input type="hidden" id="selectedStyleIdExtendId" name="selectedStyleId"/>
		<input id="selectedStyleIdExtendName" name="selectedStyleName" placeholder="" autocomplete="off" type="text" style="float:left;" class="layui-input" />
	</td>
	<td colspan="1">
		<button type="button" class="layui-btn layui-btn-sm" id="selectedStyle-select-btn">选择</button>
	</td>
</tr>
<tr class="extend">
	<td colspan="4">
		<button class="layui-btn layui-btn-sm" lay-filter="submitBizLayerForm" lay-submit>保存</button>
	</td>
</tr>
</script>
<script type="text/html" id="modelBizLayerCommon">
<tr class="common">
	<td colspan="4">
		<button class="layui-btn layui-btn-sm" lay-filter="submitBizLayerForm" lay-submit>保存</button>
	</td>
</tr>
</script>

<!-- 表单弹窗 -->
 <script type="text/html" id="modelBizLayerStyle">
	<div class="layui-tab layui-tab-card" style="margin:0px;margin-top:1px;box-shadow: none;">
	  <ul class="layui-tab-title">
	    <li class="layui-this">点</li>
	    <li>线</li>
	    <li>面</li>
	  </ul>
	  <div class="layui-tab-content" style="padding: 0px;">
	    <div class="layui-tab-item layui-show">
			<div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button lay-filter="styleForPointSearch" lay-submit class="layui-btn icon-btn" ><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </div>
			<table class="layui-table" id="tableStyleBizPoint" lay-filter="tableStyleBizPoint" style="margin: 1px;"></table>
			<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;margin: 5px;float: right;">
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPointDefaultStyleBtn">
					<i class="layui-icon">&#xe605;</i>默认
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPointHoverStyleBtn">
					<i class="layui-icon">&#xe605;</i>悬浮
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPointSelectedStyleBtn">
					<i class="layui-icon">&#xe605;</i>选中
				</button>
			</div>
		</div>
	    <div class="layui-tab-item">
			<div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button lay-filter="styleForLineSearch" lay-submit  class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </div>
			<table class="layui-table" id="tableBizStyleLine" lay-filter="tableBizStyleLine" style="margin: 1px;"></table>
			<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;margin: 5px;float: right;">
				<button class="layui-btn icon-btn layui-btn-sm" id="bizLineDefaultStyleBtn">
					<i class="layui-icon">&#xe605;</i>默认
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizLineHoverStyleBtn">
					<i class="layui-icon">&#xe605;</i>悬浮
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizLineSelectedStyleBtn">
					<i class="layui-icon">&#xe605;</i>选中
				</button>
			</div>
		</div>
	    <div class="layui-tab-item">
			<div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">搜索：</label>
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button lay-filter="styleForPolygonSearch" lay-submit  class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </div>
			<table class="layui-table" id="tableBizStylePolygon" lay-filter="tableBizStylePolygon" style="margin: 1px;"></table>
			<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;margin: 5px;float: right;">
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPolygonDefaultStyleBtn">
					<i class="layui-icon">&#xe605;</i>默认
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPolygonHoverStyleBtn">
					<i class="layui-icon">&#xe605;</i>悬浮
				</button>
				<button class="layui-btn icon-btn layui-btn-sm" id="bizPolygonSelectedStyleBtn">
					<i class="layui-icon">&#xe605;</i>选中
				</button>

			</div>
		</div>
	  </div>
	</div>   
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="modelBizLayerCommonStyle">
<div class="layui-form toolbar">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label w-auto">搜索：</label>
			<div class="layui-input-inline mr0">
				<input name="name" class="layui-input" type="text" placeholder="输入关键字" />
			</div>
		</div>
		<div class="layui-inline">
			<button lay-filter="styleForCommonSearch" lay-submit class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
			</button>
		</div>
	</div>
</div>
<table class="layui-table" id="tableStyleBizCommon" lay-filter="tableStyleBizCommon" style="margin: 1px;"></table>
<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;margin: 5px;float: right;">
	<button class="layui-btn icon-btn layui-btn-sm" id="bizPointStyleBtn">
		<i class="layui-icon">&#xe605;</i>确定
	</button>
</div>
</script>

<!-- js部分 -->
<SCRIPT type="text/javascript">
layui.use(['layer','form','upload'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
	var form =layui.form;
	var upload =layui.upload;
	var setting = {
		async: {
			enable: true,
			url: "#(ctx)/biz/layer/getAsyncTreeData?sceneId=#(sceneId)",
			autoParam:["id", "name=n", "level=lv","type=type"],
			dataFilter: filter,
		},
		view: {
			expandSpeed:"",
			addHoverDom: addHoverDom,
			removeHoverDom: removeHoverDom,
			selectedMulti: false
		},
		check: {
			enable: true,
		},
		edit: {
			drag: {
				autoExpandTrigger: true,
				prev: dropPrev,
				inner: dropInner,
				next: dropNext
			},
			enable: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		callback: {
			onCheck: onCheck,
			//onClick:onClick,
			beforeDblClick:beforeDblClick,
			onDrop:onDrop,
			beforeDrag: beforeDrag,

		}
	};
	
	function filter(treeId, parentNode, childNodes) {
		if (!childNodes) return null;
		for (var i=0, l=childNodes.length; i<l; i++) {
			childNodes[i].name = childNodes[i].name?childNodes[i].name.replace(/\.n/g, '.'):'未命名';
			if(childNodes[i].type=='point'){
				childNodes[i].icon = "#(ctx)/assets/plugins/zTree_v3/css/metroStyle/img/icon-point.png";
			}
			else if(childNodes[i].type=='line'){
				childNodes[i].icon = "#(ctx)/assets/plugins/zTree_v3/css/metroStyle/img/icon-line.png";
			}
		}
		return childNodes;
	}
	
	function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
		var zTree = $.fn.zTree.getZTreeObj("bizLayerTree");
		for(var i=0;i<treeNodes.length;i++){
			var index = zTree.getNodeIndex(treeNodes[i]);
	        var formData={}; 
	        formData['bizLayer.id']=treeNodes[i].id;
	        formData['bizLayer.parentId']=targetNode?targetNode.id:'root';
	        formData['bizLayer.sort']=index;
	        common_ajax.ajaxFunc("#(ctx)/biz/layer/save",formData, "json", null);
		}
	}
	function dropPrev(treeId, nodes, targetNode) {
		var pNode = targetNode.getParentNode();
		if (pNode && pNode.type != 'folder' && pNode.type != 'Folder' && pNode.type != 'Models' && pNode.type != 'Points' && pNode.type != 'Lines' && pNode.type != 'Polygons') {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				var curPNode = curDragNodes[i].getParentNode();
				if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}
	function dropInner(treeId, nodes, targetNode) {
		if (targetNode && targetNode.type != 'folder' && targetNode.type != 'Folder' && targetNode.type != 'Models' && targetNode.type != 'Points' && targetNode.type != 'Lines' && targetNode.type != 'Polygons') {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				if (!targetNode && curDragNodes[i].dropRoot === false) {
					return false;
				} else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}
	function dropNext(treeId, nodes, targetNode) {
		var pNode = targetNode.getParentNode();
		if (pNode && pNode.type != 'folder' && pNode.type != 'Folder' && pNode.type != 'Models' && pNode.type != 'Points' && pNode.type != 'Lines' && pNode.type != 'Polygons') {
			return false;
		} else {
			for (var i=0,l=curDragNodes.length; i<l; i++) {
				var curPNode = curDragNodes[i].getParentNode();
				if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
					return false;
				}
			}
		}
		return true;
	}

	var log, className = "dark", curDragNodes, autoExpandNode;
	function beforeDrag(treeId, treeNodes) {
		className = (className === "dark" ? "":"dark");
		for (var i=0,l=treeNodes.length; i<l; i++) {
			if (treeNodes[i].drag === false) {
				curDragNodes = null;
				return false;
			} else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
				curDragNodes = null;
				return false;
			}
		}
		curDragNodes = treeNodes;
		return true;
	}
	
	function onCheck(e, treeId, treeNode) {
		editMarker.showOrHideLayer(treeNode);
	}
	
	function onClick(event, treeId, treeNode){
		//editMarker.onClickLayer(treeNode);
	}
	
	function batch(treeNode){
		//updateNodeStatu(treeNode);
		if('map'==treeNode.type || 'terrain'==treeNode.type){
			if(treeNode.checked){
				getBizMapById(treeNode.id)
			}else{
				editMarker.scenePrimitiveForRemove({
         			id:treeNode.id,
         			type:treeNode.type
         		});
			}
		}else{
			editMarker.scenePrimitiveForShow({
				id:treeNode.id,
				type:treeNode.type,
				show:treeNode.checked
			})
		}
	}
	
	function beforeDblClick (treeId, treeNode) {
		if(treeNode){
			if (treeNode && treeNode.isParent) {
				return true;
			} else {
				editMarker.clickLayerNode(treeNode);
				return false;
			}
		}
	}

	/**
		添加鼠标事件	
	*/
	function addHoverDom(treeId, treeNode) {
		var sObj = $("#" + treeNode.tId + "_span");
		if( ('folder'==treeNode.type || 'Folder'==treeNode.type) &&  !$("#editFolderBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editFolderBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delFolderBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editFolderBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			
			var delBtn = $("#delFolderBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		if('Points'==treeNode.type &&  !$("#editPointsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editPointsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button mark-point' id='markPointBtn_" + treeNode.tId+ "' title='添加位置' onfocus='this.blur();'></span>";
			addStr += "<span class='button altitude' id='altitudePointsBtn_" + treeNode.tId+ "' title='高程' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delPointsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editPointsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			
			var markPoint = $("#markPointBtn_"+treeNode.tId);
			if (markPoint) markPoint.bind("click", function(){
				editMarker.markPoint(treeNode) 
				return false;
			});
			
			var altitudePointsBtn = $("#altitudePointsBtn_"+treeNode.tId);
			if (altitudePointsBtn) altitudePointsBtn.bind("click", function(){
				return false;
			});
			
			var delBtn = $("#delPointsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Point'==treeNode.type &&  !$("#editPointBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editPointBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delPointBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editPointBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editPoint(treeNode) 
				return false;
			});
			var delBtn = $("#delPointBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		if('Maps'==treeNode.type &&  !$("#delMapsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editMapsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button map' id='selectMapsBtn_" + treeNode.tId+ "' title='底图' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delMapsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editMapsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var selectMapsBtn = $("#selectMapsBtn_"+treeNode.tId);
			if (selectMapsBtn) selectMapsBtn.bind("click", function(){
				editMarker.addOnLineProvider(treeNode);
				return false;
			});
			var delBtn = $("#delMapsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Map'==treeNode.type &&  !$("#upMapBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button up' id='upMapBtn_" + treeNode.tId+ "' title='上移' onfocus='this.blur();'></span>";
			addStr += "<span class='button down' id='downMapBtn_" + treeNode.tId+ "' title='下移' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delMapBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editMapBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editProvider(treeNode);
				return false;
			});
			var delBtn = $("#delMapBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		if('Models'==treeNode.type && !$("#editModelsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editModelsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button model' id='selectModelsBtn_" + treeNode.tId+ "' title='资源库选模型' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delModelsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editModelsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			
			var selectModelsBtn = $("#selectModelsBtn_"+treeNode.tId);
			if (selectModelsBtn) selectModelsBtn.bind("click", function(){
				editMarker.addOnLineModel(treeNode);
				return false;
			});
			var delBtn = $("#delModelsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Model'==treeNode.type &&  !$("#editModelBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editModelBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr+= "<span class='button remove' id='delModelBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			
			var editBtn = $("#editModelBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editModel(treeNode);
				return false;
			});
			var delBtn = $("#delModelBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		if('Polylines'==treeNode.type &&  !$("#editLinesBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editLinesBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button polyline' id='drawLinesBtn_" + treeNode.tId+ "' title='样式' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delLinesBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editLinesBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			
			var drawLinesBtn = $("#drawLinesBtn_"+treeNode.tId);
			if (drawLinesBtn) drawLinesBtn.bind("click", function(){
				editMarker.drawPolyline(treeNode);
				return false;
			});
			
			var delBtn = $("#delLinesBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Polyline'==treeNode.type &&  !$("#editLineBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editLineBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delLineBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editLineBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editPolyLine(treeNode.id,treeNode.name) 
				return false;
			});
			
			
			var delBtn = $("#delLineBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		if('Polygons'==treeNode.type &&  !$("#editPolygonsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editPolygonsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button polygon' id='drawPolygonsBtn_" + treeNode.tId+ "' title='样式' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delPolygonsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editPolygonsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			
			var drawPolygonsBtn = $("#drawPolygonsBtn_"+treeNode.tId);
			if (drawPolygonsBtn) drawPolygonsBtn.bind("click", function(){
				editMarker.drawPolygon(treeNode);
				return false;
			});
			
			var delBtn = $("#delPolygonsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Polygon'==treeNode.type &&  !$("#editPolygonBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editPolygonBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delPolygonBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editPolygonBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editPolygon(treeNode.id,treeNode.name) 
				return false;
			});
			
			var delBtn = $("#delPolygonBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Features'==treeNode.type &&  !$("#editFeaturestBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editFeaturestBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button feature' id='drawFeaturesBtn_" + treeNode.tId+ "' title='绘制单体' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delFeaturestBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editFeaturestBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var drawFeaturesBtn = $("#drawFeaturesBtn_"+treeNode.tId);
			if (drawFeaturesBtn) drawFeaturesBtn.bind("click", function(){
				editMarker.drawFeature(treeNode);
				return false;
			});
			var delBtn = $("#delFeaturestBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Feature'==treeNode.type &&  !$("#editFeaturetBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editFeaturetBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delFeatureBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editFeaturetBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editFeature(treeNode.id,treeNode.name) 
				return false;
			});
			var delBtn = $("#delFeatureBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoPlanes'==treeNode.type &&  !$("#editVideoPlanesBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoPlanesBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button vplane' id='drawVideoPlanesBtn_" + treeNode.tId+ "' title='视频墙' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoPlanesBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoPlanesBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var drawVideoPlanesBtn = $("#drawVideoPlanesBtn_"+treeNode.tId);
			if (drawVideoPlanesBtn) drawVideoPlanesBtn.bind("click", function(){
				editMarker.editVideoPlane(treeNode);
				return false;
			});
			var delBtn = $("#delVideoPlanesBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoPlane'==treeNode.type &&  !$("#editVideoPlaneBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoPlaneBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoPlaneBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoPlaneBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editVideoPlane(treeNode);
				return false;
			});
			var delBtn = $("#delVideoPlaneBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoShed3ds'==treeNode.type &&  !$("#editVideoShed3dsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoShed3dsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button vplane' id='drawVideoShed3dsBtn_" + treeNode.tId+ "' title='视频墙' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoShed3dsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoShed3dsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var drawVideoShed3dsBtn = $("#drawVideoShed3dsBtn_"+treeNode.tId);
			if (drawVideoShed3dsBtn) drawVideoShed3dsBtn.bind("click", function(){
				editMarker.editVideoShed3d(treeNode);
				return false;
			});
			var delBtn = $("#delVideoShed3dsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoShed3d'==treeNode.type &&  !$("#editVideoShed3dBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoShed3dBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoShed3dBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoShed3dBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editVideoShed3d(treeNode);
				return false;
			});
			var delBtn = $("#delVideoShed3dBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoModels'==treeNode.type &&  !$("#editVideoModelsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoModelsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button vplane' id='drawVideoModelsBtn_" + treeNode.tId+ "' title='视频墙' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoModelsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoModelsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var drawVideoModelsBtn = $("#drawVideoModelsBtn_"+treeNode.tId);
			if (drawVideoModelsBtn) drawVideoModelsBtn.bind("click", function(){
				editMarker.editVModel(treeNode);
				return false;
			});
			var delBtn = $("#delVideoModelsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('VideoModel'==treeNode.type &&  !$("#editVideoModelBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editVideoModelBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delVideoModelBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editVideoModelBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editVModel(treeNode);
				return false;
			});
			var delBtn = $("#delVideoModelBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		//漫游
		else if('Roams'==treeNode.type &&  !$("#editRoamsBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editRoamsBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button roam' id='drawRoamsBtn_" + treeNode.tId+ "' title='漫游' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delRoamsBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editRoamsBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				addFolder(treeNode);
				return false;
			});
			var drawRoamsBtn = $("#drawRoamsBtn_"+treeNode.tId);
			if (drawRoamsBtn) drawRoamsBtn.bind("click", function(){
				editMarker.addRoam(treeNode);
				return false;
			});
			var delBtn = $("#delRoamsBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('Roam'==treeNode.type &&  !$("#editRoamBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editRoamBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button roamRoad' id='drawRoamBtn_" + treeNode.tId+ "' title='绘制漫游路线' onfocus='this.blur();'></span>";
			addStr += "<span class='button roamDoing' id='roamDoingBtn_" + treeNode.tId+ "' title='运行' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delRoamBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editRoamBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.editRoam(treeNode);
				return false;
			});
			var drawRoamBtn = $("#drawRoamBtn_"+treeNode.tId);
			if (drawRoamBtn) drawRoamBtn.bind("click", function(){
				editMarker.addRoamRoad(treeNode);
				return false;
			});
			
			var roamDoingBtn = $("#roamDoingBtn_"+treeNode.tId);
			if (roamDoingBtn) roamDoingBtn.bind("click", function(){
				editMarker.doingRoam(treeNode);
				return false;
			});
			
			var delBtn = $("#delRoamBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('RoamPoint'==treeNode.type &&  !$("#editRoamPointBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editRoamPointBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr += "<span class='button remove' id='delRoamPointBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editRoamPointBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				//editMarker.editRoamPoint(treeNode);
				return false;
			});
			var delBtn = $("#delRoamPointBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				editMarker.deleteLayer(treeNode);
				return false;
			});
		}
		else if('view'==treeNode.type &&  !$("#editBizViewBtn_"+treeNode.tId).length>0){
			var addStr= "<span class='button edit' id='editBizViewBtn_" + treeNode.tId+ "' title='编辑' onfocus='this.blur();'></span>";
			addStr+= "<span class='button remove' id='eventBizViewBtn_" + treeNode.tId+ "' title='事件' onfocus='this.blur();'></span>";
			addStr+= "<span class='button remove' id='delBizViewBtn_" + treeNode.tId+ "' title='删除' onfocus='this.blur();'></span>";
			sObj.after(addStr);
			var editBtn = $("#editBizViewBtn_"+treeNode.tId);
			if (editBtn) editBtn.bind("click", function(){
				editMarker.viewForEdit(treeNode.id,treeNode.name);
				return false;
			});
			
			var eventBtn = $("#eventBizViewBtn_"+treeNode.tId);
			if (eventBtn) eventBtn.bind("click", function(){
				editMarker.viewForEvent(treeNode.id,treeNode.name);
				return false;
			});
			
			var delBtn = $("#delBizViewBtn_"+treeNode.tId);
			if (delBtn) delBtn.bind("click", function(){
				del(treeNode);
				return false;
			});
		}

	};
	function removeHoverDom(treeId, treeNode) {
		$("#editFolderBtn_"+treeNode.tId).unbind().remove();
		$("#delFolderBtn_"+treeNode.tId).unbind().remove();
		
		//点集合
		$("#editPointsBtn_"+treeNode.tId).unbind().remove();
		$("#markPointBtn_"+treeNode.tId).unbind().remove();
		$("#delPointsBtn_"+treeNode.tId).unbind().remove();
		$("#altitudePointsBtn_"+treeNode.tId).unbind().remove();
		
		//点
		$("#editPointBtn_"+treeNode.tId).unbind().remove();
		$("#delPointBtn_"+treeNode.tId).unbind().remove();

		
		
		//面集合
		$("#editPolygonsBtn_"+treeNode.tId).unbind().remove();
		$("#drawPolygonsBtn_"+treeNode.tId).unbind().remove();
		$("#delPolygonsBtn_"+treeNode.tId).unbind().remove();
		//面
		$("#editPolygonBtn_"+treeNode.tId).unbind().remove();
		$("#delPolygonBtn_"+treeNode.tId).unbind().remove();
		
		
		//线
		$("#editLinesBtn_"+treeNode.tId).unbind().remove();
		$("#drawLinesBtn_"+treeNode.tId).unbind().remove();
		$("#delLinesBtn_"+treeNode.tId).unbind().remove();	
		
		$("#editLineBtn_"+treeNode.tId).unbind().remove();
		$("#delLineBtn_"+treeNode.tId).unbind().remove();

		$("#editFeaturetBtn_"+treeNode.tId).unbind().remove();
		$("#delFeatureBtn_"+treeNode.tId).unbind().remove();
		
		
		//在线底图
		$("#editMapsBtn_"+treeNode.tId).unbind().remove();
		$("#selectMapsBtn_"+treeNode.tId).unbind().remove();
		$("#delMapsBtn_"+treeNode.tId).unbind().remove();
		$("#upMapBtn_"+treeNode.tId).unbind().remove();
		$("#downMapBtn_"+treeNode.tId).unbind().remove();
		$("#delMapBtn_"+treeNode.tId).unbind().remove();
		
		
		$("#delTerrainBtn_"+treeNode.tId).unbind().remove();
		$("#delDivisionBtn_"+treeNode.tId).unbind().remove();
		$("#delRoadBtn_"+treeNode.tId).unbind().remove();
		
		//删除模型
		$("#editModelsBtn_"+treeNode.tId).unbind().remove();
		$("#delModelsBtn_"+treeNode.tId).unbind().remove();
		$("#selectModelsBtn_"+treeNode.tId).unbind().remove();
		
		
		$("#delModelBtn_"+treeNode.tId).unbind().remove();
		$("#editModelBtn_"+treeNode.tId).unbind().remove();
		
		
		//单体
		$("#editFeaturestBtn_"+treeNode.tId).unbind().remove();
		$("#delFeaturestBtn_"+treeNode.tId).unbind().remove();
		$("#drawFeaturesBtn_"+treeNode.tId).unbind().remove();
		
		$("#editVideoPlanesBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoPlanesBtn_"+treeNode.tId).unbind().remove();
		$("#drawVideoPlanesBtn_"+treeNode.tId).unbind().remove();
		$("#editVideoPlaneBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoPlaneBtn_"+treeNode.tId).unbind().remove();
		
		
		$("#editVideoShed3dsBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoShed3dsBtn_"+treeNode.tId).unbind().remove();
		$("#drawVideoShed3dsBtn_"+treeNode.tId).unbind().remove();
		$("#editVideoShed3dBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoShed3dBtn_"+treeNode.tId).unbind().remove();
		
		$("#editVideoModelsBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoModelsBtn_"+treeNode.tId).unbind().remove();
		$("#drawVideoModelsBtn_"+treeNode.tId).unbind().remove();
		$("#editVideoModelBtn_"+treeNode.tId).unbind().remove();
		$("#delVideoModelBtn_"+treeNode.tId).unbind().remove();

		$("#editRoamsBtn_"+treeNode.tId).unbind().remove();
		$("#delRoamsBtn_"+treeNode.tId).unbind().remove();
		$("#drawRoamsBtn_"+treeNode.tId).unbind().remove();
		$("#editRoamPointBtn_"+treeNode.tId).unbind().remove();
		$("#delRoamPointBtn_"+treeNode.tId).unbind().remove();
		
		$("#editRoamBtn_"+treeNode.tId).unbind().remove();
		$("#delRoamBtn_"+treeNode.tId).unbind().remove();
		$("#drawRoamBtn_"+treeNode.tId).unbind().remove();
		$("#roamDoingBtn_"+treeNode.tId).unbind().remove();
		
		$("#delGLTFBtn_"+treeNode.tId).unbind().remove();
		$("#del3DTILESBtn_"+treeNode.tId).unbind().remove();
		$("#edit3DTILESBtn_"+treeNode.tId).unbind().remove();
		
		$("#editBizViewBtn_"+treeNode.tId).unbind().remove();
		$("#delBizViewBtn_"+treeNode.tId).unbind().remove();
		$("#eventBizViewBtn_"+treeNode.tId).unbind().remove();
		
		
	};
	$(document).ready(function(){
		$.fn.zTree.init($("#bizLayerTree"), setting);
		sceneTree= $.fn.zTree.getZTreeObj("bizLayerTree");
	});
		
	$('#btnAddBizLayerFolder').click(function () {
		 addFolder();
	});
	
	function updateNodeStatu(treeNode){
        layer.load(2);
        var formData={}; 
        formData['bizLayer.id']=treeNode.id;
        formData['bizLayer.show']=treeNode.checked?'1':'0';
        common_ajax.ajaxAsyncFunc(ctx+"/biz/layer/save",formData, "json", function(res){
            layer.closeAll('loading');
            if (200==res.code) {
                layer.msg(res.message, {icon: 1});
            } else {
                layer.msg(res.message, {icon: 2});
            }
        });

	}
	
	function addFolder(data){
        layer.open({
            type: 1,
            title: '图层目录',
            content: $('#modelBizLayer').html(), 
            area:'400px',
            offset: 't',
            success: function (layero, dIndex) {
           	 	$(layero).children('.layui-layer-content').css('overflow', 'visible');
           	 	if(data){
           	 		var children = data.children;
           	 		layer.load(2);
           	 		common_ajax.ajaxAsyncFunc(ctx+"/biz/layer/getLayerById",{id:data.id}, "json", function(res){
               	 	 	layer.closeAll('loading');
               	 		if(200==res.code){
               	 			data=res.data;
               	 			if(data.type=='Points' || data.type=='Polylines' || data.type=='Polygons'){
               	 				$('#modelBizLayerFormTable').append($('#modelBizLayerExtend').html());
               	 				//默认样式
               		    		$('#defaultStyle-select-btn').click(function () {
               		    			settingCommonStyle(selectType,'default');
               		    			return false;
               	    			});
               		    		$('#hoverStyle-select-btn').click(function () {
               		    			settingCommonStyle(selectType,'hover');
               		    			return false;
               	    			});
               		    		$('#selectedStyle-select-btn').click(function () {
               		    			settingCommonStyle(selectType,'selected');
               		    			return false;
               	    			});
               	 			}else{
               	 				$('#modelBizLayerFormTable').append($('#modelBizLayerCommon').html());
               	 			}
               	 		}else{
               	 			layer.close(dIndex);
               	 		 	layer.msg(res.message, {icon: 2});
            	    		var zTree = $.fn.zTree.getZTreeObj("bizLayerTree");
            	    		if(zTree){
            	    			var node =zTree.getNodeByParam("id",data.id);
            	    			if(node){
            	    				zTree.removeNode(node);
            	    			}
            	    		}
               	 		 	return;
               	 		}
               	 		if(data.type!='Folder' && children && children.length>0) 
               	 			$("#lsyerTypeSelectId").attr('disabled','disabled');
                        form.val('modelBizLayerForm', data); 
           	 		});
           	 	}else{
           	 		$('#modelBizLayerFormTable').append($('#modelBizLayerCommon').html());
           	 	}
           	 	
           	 	var selectType = data?data.type:'',dataObj = data;
	           	form.on('select(type)', function(data){
	           		selectType = data.value;
	         		if(data.value=='Points' || data.value=='Polylines' || data.value=='Polygons'){
	         			if($('.extend').length>0)return;
	         			$('.common').remove();
	         			$('#modelBizLayerFormTable').append($('#modelBizLayerExtend').html());
	         			//默认样式
	    	    		$('#defaultStyle-select-btn').click(function () {
	    	    			settingCommonStyle(selectType,'default');
	    	    			return false;
	        			});
	    	    		$('#hoverStyle-select-btn').click(function () {
	    	    			settingCommonStyle(selectType,'hover');
	    	    			return false;
	        			});
	    	    		$('#selectedStyle-select-btn').click(function () {
	    	    			settingCommonStyle(selectType,'selected');
	    	    			return false;
	        			});
	    	    		if(dataObj)form.val('modelBizLayerForm', dataObj); 
	         		}else{
	         			if($('.common').length>0)return;
	         			$('.extend').remove();
	         			$('#modelBizLayerFormTable').append($('#modelBizLayerCommon').html());
	         		}
	            });
	           	
                // 表单提交事件
                form.on('submit(submitBizLayerForm)', function (fData) {
                    if (fData.field.parentId == '') {
                    	fData.field.parentId = 'root';
                    }
                    layer.load(2);
                    var formData={}; 
                    for(var key in fData.field){
                    	if(key!='defaultStyleName' && key!='hoverStyleName' && key!='selectedStyleName'){
                    		formData['bizLayer.'+key]=fData.field[key];
                    	}
                    }
			        common_ajax.ajaxAsyncFunc(ctx+"/biz/layer/save",formData, "json", function(res){
				        layer.closeAll('loading');
				        if (200==res.code) {
				        	layer.close(dIndex);
				            layer.msg(res.message, {icon: 1});
				            var newNode=res.data;
							var zTree = $.fn.zTree.getZTreeObj("bizLayerTree");
							if(zTree){
								if(!data){
	    							var treeNode =zTree.getNodeByParam("id",newNode.parentId);
	    							zTree.addNodes(treeNode?treeNode:null, {id:newNode.id, pId:newNode.parentId, name:newNode.name,type:newNode.type});
								}else{
									var editNode =zTree.getNodeByParam("id",res.data.id);
									if(editNode){
										editNode.name=res.data.name;
										zTree.updateNode(editNode);
									}
								}
							}
				        } else {
				            layer.msg(res.message, {icon: 2});
				        }
			        });
                    return false;
                });
                form.render();
           	 	
           	 	
            }
        });
	}
	
	//获取图层详情
	function getBizMapById(id){
 		common_ajax.ajaxAsyncFunc(ctx+"/biz/map/getById",{layerId:id}, "json", function(res){
 	 		if(200==res.code){
 	 			var data =res.data;
 	 				data.show='1';
 	    		var maps=[data];
 	    		editMarker.addImageryProvidersFromServ(maps);
 	 		}
 		});
	}
	
    upload.render({
  	        elem: '#btnImportFileKml'
  	        ,url: '#(ctx)/biz/kml/uploadForKml'
  	        ,accept: 'file'
  	        ,exts: 'kml'
  	       	,data: {
  	       		sceneId:'#(sceneId)'
  	       	}
  	     	,before: function(obj){ 
  	  	    	layer.load(); 
  	  	    }
  	  	    ,done: function(res, index, upload){
  	  			layer.closeAll('loading');
  	          	if (200==res.code) {
  	              layer.msg(res.message, {icon: 1});
  	          	} else {
  	              layer.msg(res.message, {icon: 2});
  	          	}
  	  	    }
  	  	    ,error: function(index, upload){
  	  	     	layer.closeAll('loading');
  	  		 	layer.close(dIndex);
  	  	     	layer.msg("上传失败！", {icon: 2});
  	  	   }       
  	   });

    
    function settingCommonStyle(type,event){
    	console.log(type,event);
    	layer.open({
            type: 1,
            title: '图层样式',
            content: $('#modelBizLayerCommonStyle').html(),
            area:'400px',
            offset: 't',
            success: function (layero, dIndex) {
           	 	$(layero).children('.layui-layer-content').css('overflow', 'visible');
           	 	var url='',cols=[[
                    {type:'radio'},
                    {field: 'name', sort: false, title: '名称'},
                ]];
           	 	if(type==='Points'){
           	 		url = '#(ctx)/biz/style/point/listData';
           	 		cols = [[
	                    {type:'radio'},
	                    {
	                        align: 'center', templet: function (d) {
	                        	if(d.imageForBillboard)
	                            	return '<img src="#(ctx)'+d.imageForBillboard+'" class="tdImg" />';
	                            else
	                            	return '';
	                        }, title: '缩略图', width: 100, unresize: true
	                    },
	                    {field: 'name', sort: false, title: '名称'},
	                ]];
           	 	}else if(type==='Polylines'){
           	 		url = '#(ctx)/biz/style/line/listData';
           	 	}else if(type==='Polygons'){
           	 		url = '#(ctx)/biz/style/polygon/listData';
           	 	}else{
           	 		return;
           	 	}
	            var insTbForBizCommonIcon = table.render({
	                elem: '#tableStyleBizCommon',
	                url: url, 
	                page: true,
	                cellMinWidth: 100,
	                height:700,
	                cols: cols
	            });
	            
	         	// 搜索
	            form.on('submit(styleForCommonSearch)', function (data) {
	            	insTbForBizCommonIcon.reload({where: data.field}, 'data');
	            });
	            
	            //默认样式
	    		$('#bizPointStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableStyleBizCommon"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.close(dIndex);
	    	        	if(event==='default'){
	    	        		$('#defaultStyleIdExtendId').val(styles[0].id);
	    	        		$('#defaultStyleIdExtendName').val(styles[0].name);
	    	        	}else if(event==='hover'){
	    	        		$('#hoverStyleIdExtendId').val(styles[0].id);
	    	        		$('#hoverStyleIdExtendName').val(styles[0].name);
	    	        	}else if(event==='selected'){
	    	        		$('#selectedStyleIdExtendId').val(styles[0].id);
	    	        		$('#selectedStyleIdExtendName').val(styles[0].name);
	    	        	}else{
	    	        		
	    	        	}
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
            }
        });
    }
    
    //设置样式
	function settingStyle(data){
        layer.open({
            type: 1,
            title: '图层样式',
            content: $('#modelBizLayerStyle').html(),
            area:'400px',
            offset: 't',
            success: function (layero, dIndex) {
           	 	$(layero).children('.layui-layer-content').css('overflow', 'visible');
	            var insTbForBizPointIcon = table.render({
	                elem: '#tableStyleBizPoint',
	                url: '#(ctx)/biz/style/point/listData', 
	                page: true,
	                cellMinWidth: 100,
	                height:700,
	                cols: [[
	                    {type:'radio'},
	                    {
	                        align: 'center', templet: function (d) {
	                        	if(d.imageForBillboard)
	                            	return '<img src="#(ctx)'+d.imageForBillboard+'" class="tdImg" />';
	                            else
	                            	return '';
	                        }, title: '缩略图', width: 100, unresize: true
	                    },
	                    {field: 'name', sort: false, title: '名称'},
	                ]]
	            });
	            
	         	// 搜索
	            form.on('submit(styleForPointSearch)', function (data) {
	            	insTbForBizPointIcon.reload({where: data.field}, 'data');
	            });
	            
	            //默认样式
	    		$('#bizPointDefaultStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableStyleBizPoint"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='DEFAULT';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/point/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //悬浮
	    		$('#bizPointHoverStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableStyleBizPoint"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='HOVER';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/point/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //选中
	    		$('#bizPointSelectedStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableStyleBizPoint"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='SELECTED';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/point/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});	
	            
	    		
	            var insLineStyleTb = table.render({
	                elem: '#tableBizStyleLine',
	                url: '#(ctx)/biz/style/line/listData', 
	                page: true,
	                toolbar: false,
	                cellMinWidth: 100,
	                cols: [[
	                	{type:'radio'},
	                    {field: 'name', sort: false, title: '名称'},
	                ]],
	            });
	            
	            form.on('submit(styleForLineSearch)', function (data) {
	            	insLineStyleTb.reload({where: data.field}, 'data');
	            });
	            
	            //默认样式
	    		$('#bizLineDefaultStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStyleLine"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='DEFAULT';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/line/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //悬浮
	    		$('#bizLineHoverStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStyleLine"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='HOVER';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/line/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //选中
	    		$('#bizLineSelectedStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStyleLine"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='SELECTED';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/line/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});	
	    		
	    		
	    		
	            var insPolygonStyleTb = table.render({
	                elem: '#tableBizStylePolygon',
	                url: '#(ctx)/biz/style/polygon/listData', 
	                page: true,
	                toolbar: false,
	                cellMinWidth: 100,
	                cols: [[
	                	{type:'radio'},
	                    {field: 'name', sort: false, title: '名称'},
	                ]],
	            });
	            
	            form.on('submit(styleForPolygonSearch)', function (data) {
	            	insPolygonStyleTb.reload({where: data.field}, 'data');
	            });
	            
	            //默认样式
	    		$('#bizPolygonDefaultStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStylePolygon"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='DEFAULT';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/polygon/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //悬浮
	    		$('#bizPolygonHoverStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStylePolygon"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='HOVER';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/polygon/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
	            
	            //选中
	    		$('#bizPolygonSelectedStyleBtn').click(function () {
	    			var checkStatus = table.checkStatus("tableBizStylePolygon"); //获取选中行状态
	    	        var styles = checkStatus.data;  //获取选中行数据
	    	        if(styles && styles.length>0){
	    	        	layer.load(2);
	    	            var formData={}; 
	    	            formData['layerId']=data.id;
	    	            formData['styleId']=styles[0].id;
	    	            formData['event']='SELECTED';
	    	            common_ajax.ajaxAsyncFunc("#(ctx)/biz/marker/polygon/batchSaveStyle",formData, "json", function(res){
	    		            layer.closeAll('loading');
	    		            if (undefined!=res && 200==res.code) {
	    		                layer.msg(res.message, {icon: 1});
	    		            } else {
	    		                layer.msg(res.message, {icon: 2});
	    		            }
	    		        	layer.close(dIndex);
	    	            });
	    	        }else{
	    	        	layer.msg("请选择样式!!!", {icon: 3});
	    	        }
	    	        return false;
    			});
            }
        });
	}   
    
    
    
    
});

var _Ajax = function(reqType, url, data, dataType, callback) {
	$.ajax({
		type: reqType,
		url: encodeURI(encodeURI(url)),
		data: data,
		dataType: dataType ? dataType : 'html',
		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		async: false,
		cache: false,
		success: function(response) {
			if (callback != null) {
				callback(response);
			}
		}
	});
}


	
</SCRIPT>